package ITSBank;


import java.io.IOException;
import java.util.ArrayList;

/**
 * This abstract class represents the overall class for different kinds of accounts.
 * It holds all necessary information for an account.
 * @author Benedikt Gschossmann
 */
public abstract class Account {
    protected int AccountNumber;
    protected int CustomerID;
    protected float Balance;
    protected Bank BankID;
    protected ArrayList<Transaction> TransactionHistory;

    /**
     * get-method for balance
     * @return balance of the account
     */
    public float getBalance () {
        return Balance;
    }

    /**
     * get-method for cID
     * @return cID of the account owner
     */
    public int getCustomerID () {
        return CustomerID;
    }

    public ArrayList<Transaction> getTransactionHistory() {
        return TransactionHistory;
    }
    
    /**
     * This method displays all transactions for the account
     * @return balance of the account
     */
    public void displayTransactionHistory () {
        for(int i = 0; i< TransactionHistory.size();i++){
            //TODO -> well forming of output
            TransactionHistory.get(i).displayTransaction();
        }
    }

    /**
     * This method adds a transaction to the transactionHistory
     */
    public void addTransaction (Transaction newTransaction) {
        TransactionHistory.add(newTransaction);
    }

    /**
     * get-method for accID
     * @return ID of the account
     */
    public int getAccountNumber () {
        return AccountNumber;
    }

    /**
     * get-method for bankID
     * @return bankID of the account
     */
    public Bank getBankID () {
        return BankID;
    }

    /**
     * This method withdraws the account by the given amount
     */
    public void withdraw (float amount) throws IOException {
        try{
            if (this.getBalance()<amount)
            {throw new IOException("Not enough funds!");}
            else
            {Balance -= amount;
            this.addTransaction(new Transaction(this,"withdraw",amount));
            }}
        catch(Exception e){
        System.err.println(e.getMessage()); }
    }

    /**
     * This method deposits the account by the given amount
     */
    public void deposit (float amount) {
        Balance += amount;
        this.addTransaction(new Transaction(this,"deposit",amount));
    }
}

